/**
 * 从 itemElements 中抽离出所有的imgElements
 */
export const getImgElements = (itemElements) => {
  const imgElements = [];
  itemElements.forEach((el) => {
    imgElements.push(...el.getElementsByTagName("img"));
  });
  return imgElements;
};

export const getAllImg = (imgElements) => {
  /**
   * 生成所有的图片链接数组
   */
  return imgElements.map((item) => {
    return item.src;
  });
};

// 监听图片数组加载完成（promise）
export const onComplateImg = (imgs) => {
  //promise 集合
  const promiseAll = [];
  //循环imgs，构建promiseAll
  imgs.forEach((img, index) => {
    promiseAll[index] = new Promise((resolve, reject) => {
      //处理 img的加载情况
      const imageObj = new Image();
      imageObj.src = img;
      imageObj.onload = () => {
        resolve({
          img,
          index
        });
      };
    });
  });
  return Promise.all(promiseAll);
};

/**
 * 返回列高对象中最小的高度
 */
export const getMinHeight = (columnHeightObj) => {
  const columbHeightArr =  Object.values(columnHeightObj)
  console.log('columbHeightArr',columbHeightArr)
  return Math.min(...columbHeightArr)
}

/**
 * 返回列高对象中最小的高度
 */
 export const getMaxHeight = (columnHeightObj) => {
    const columbHeightArr =  Object.values(columnHeightObj)
    return Math.max(...columbHeightArr)
  }

/**
 * 返回列高对象中最小高度所在的列
 */
export const getMinHeightColumn = (columnHeightObj) => {
    //拿到最小的高度
    const minHeight = getMinHeight(columnHeightObj)
    return Object.keys(columnHeightObj).find(key => {
        return columnHeightObj[key] === minHeight
    })
}